package main

import (
	"common/consul"
	"flag"
	"fmt"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"net"
	_ "seckill/initialization"
	"seckill/internal/server"
	pb "seckill/proto"
)

var (
	port = flag.Int("seckill", 50051, "The server port")
)

func main() {
	flag.Parse()
	lis, err := net.Listen("tcp", fmt.Sprintf(":%v", *port))
	if err != nil {
		zap.S().Error("地址监听失败")
		return
	}
	Register()
	s := grpc.NewServer()
	pb.RegisterSeckillServer(s, &server.Server{})
	zap.S().Infof("server listening at %v", lis.Addr())
	if err = s.Serve(lis); err != nil {
		zap.S().Errorf("Failed server %v", err.Error())
		return
	}
}

func Register() {
	consul.NewClient("117.27.231.112", 9000).Register("seckill", []string{}, 9000, "117.27.231.112")
}
